unique array determination

Hi friends,

I have an array

string arr[7]={"Apple","orange","orange","pineapple","Apple","Apple","orange"}

i like output to printed

Apple - 3
orange -3
pineapple -1

can you please help.
MohanRS - Mon Nov 19 13:44:26 EST 2012

Re: unique array determination
llandale - Mon Nov 19 15:02:37 EST 2012

//*********************
bool fPutSkipIncrement(Skip skpList, string KeyValue)
{ // Insert the KeyValue into the Skip list's 'Key'.
// The 'Data' portion of the Skip is set to 1 for new inserts and is
// incremented for already existing 'Key's in the Skip.
// 'Data' MUST be of type Integer.
// (represents the number of references).
// Return whether this is a first insert for KeyValue into the Skip.

bool IsNewValue = false

int NumReferences = 0 // Remains zero if next "find" doesn't find anything:
if(find(skpList, KeyValue, NumReferences))
delete(skpList, KeyValue) // Remove It
else IsNewValue = true // Mark it New
// ReInsert new or updated counts
NumReferences++
put (skpList, KeyValue, NumReferences)
return(IsNewValue)
} // end fPutSkipIncrement()

// ========== MAIN =============
string arr[7]={"Apple","orange","orange","pineapple","Apple","Apple","orange"}

int i, Count
string Fruit
Skip skpTotals = createString() // KEY 'string' fruit; DATA 'int' count

for (i=0; i<sizeof(arr); i++)
{ fPutSkipIncrement(skpTotals, arr[i])
}
for Count in skpTotals do
{ Fruit = (string key skpTotals)
print Count "\t" Fruit "\n"
}
delete(skpTotals)

Re: unique array determination
llandale - Mon Nov 19 15:03:32 EST 2012

llandale - Mon Nov 19 15:02:37 EST 2012
//*********************
bool fPutSkipIncrement(Skip skpList, string KeyValue)
{ // Insert the KeyValue into the Skip list's 'Key'.
// The 'Data' portion of the Skip is set to 1 for new inserts and is
// incremented for already existing 'Key's in the Skip.
// 'Data' MUST be of type Integer.
// (represents the number of references).
// Return whether this is a first insert for KeyValue into the Skip.

bool IsNewValue = false

int NumReferences = 0 // Remains zero if next "find" doesn't find anything:
if(find(skpList, KeyValue, NumReferences))
delete(skpList, KeyValue) // Remove It
else IsNewValue = true // Mark it New
// ReInsert new or updated counts
NumReferences++
put (skpList, KeyValue, NumReferences)
return(IsNewValue)
} // end fPutSkipIncrement()

// ========== MAIN =============
string arr[7]={"Apple","orange","orange","pineapple","Apple","Apple","orange"}

int i, Count
string Fruit
Skip skpTotals = createString() // KEY 'string' fruit; DATA 'int' count

for (i=0; i<sizeof(arr); i++)
{ fPutSkipIncrement(skpTotals, arr[i])
}
for Count in skpTotals do
{ Fruit = (string key skpTotals)
print Count "\t" Fruit "\n"
}
delete(skpTotals)

Oops

//*********************
bool    fPutSkipIncrement(Skip skpList, string KeyValue)
{     // Insert the KeyValue into the Skip list's 'Key'.
        // The 'Data' portion of the Skip is set to 1 for new inserts and is
        //    incremented for already existing 'Key's in the Skip.
        // 'Data' MUST be of type Integer.
        //   (represents the number of references).
        // Return whether this is a first insert for KeyValue into the Skip.
 
        bool    IsNewValue = false
 
        int     NumReferences = 0       // Remains zero if next "find" doesn't find anything:
        if(find(skpList, KeyValue, NumReferences))
             delete(skpList, KeyValue)          // Remove It
        else IsNewValue = true                  // Mark it New
                        // ReInsert new or updated counts
        NumReferences++
        put (skpList, KeyValue, NumReferences)
        return(IsNewValue)
}     // end fPutSkipIncrement()
 
 
 
 
 
string arr[7]={"Apple","orange","orange","pineapple","Apple","Apple","orange"}
 
int     i, Count
string  Fruit
Skip    skpTotals = createString() // KEY 'string' fruit; DATA 'int' count
 
for (i=0; i<sizeof(arr); i++)
{  fPutSkipIncrement(skpTotals, arr[i])
}
for Count in skpTotals do
{  Fruit = (string key skpTotals)
   print Count "\t" Fruit "\n"
}
delete(skpTotals)

Re: unique array determination
MohanRS - Tue Nov 20 06:53:02 EST 2012

llandale - Mon Nov 19 15:03:32 EST 2012

Oops

//*********************
bool    fPutSkipIncrement(Skip skpList, string KeyValue)
{     // Insert the KeyValue into the Skip list's 'Key'.
        // The 'Data' portion of the Skip is set to 1 for new inserts and is
        //    incremented for already existing 'Key's in the Skip.
        // 'Data' MUST be of type Integer.
        //   (represents the number of references).
        // Return whether this is a first insert for KeyValue into the Skip.
 
        bool    IsNewValue = false
 
        int     NumReferences = 0       // Remains zero if next "find" doesn't find anything:
        if(find(skpList, KeyValue, NumReferences))
             delete(skpList, KeyValue)          // Remove It
        else IsNewValue = true                  // Mark it New
                        // ReInsert new or updated counts
        NumReferences++
        put (skpList, KeyValue, NumReferences)
        return(IsNewValue)
}     // end fPutSkipIncrement()
 
 
 
 
 
string arr[7]={"Apple","orange","orange","pineapple","Apple","Apple","orange"}
 
int     i, Count
string  Fruit
Skip    skpTotals = createString() // KEY 'string' fruit; DATA 'int' count
 
for (i=0; i<sizeof(arr); i++)
{  fPutSkipIncrement(skpTotals, arr[i])
}
for Count in skpTotals do
{  Fruit = (string key skpTotals)
   print Count "\t" Fruit "\n"
}
delete(skpTotals)

It Works!!! Thanks llandale